package com.atguigu.day16.test01;

import java.util.Comparator;

/**
 * @author fenge
 */
public class Student implements Comparable<Student> {
    private String name;
    private int age;
    private double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    public Student() {
    }

    @Override
    public int compareTo(Student o) {
        int result;
        if (this.score > o.score)
            result = -1;
        else if (this.score < o.score)
            result = 1;
        else {
            if (this.age<o.age)
                result = -1;
            else if (this.age>o.age)
                result = 1;
            else
                result = 0;
        }
        return result;
    }
    /*@Override
    public int compareTo(Student o) {
        int result;
        if (this.score > o.score)
            result = -1;
        else if (this.score < o.score)
            result = 1;
        else {
            if (this.name.compareTo(o.name) > 0)
                result = 1;
            else if (this.name.compareTo(o.name) < 0)
                result = -1;
            else
                result = 0;
        }
        return result;
    }*/

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}'+'\n';
    }
}
